
/*
    此程序可用于解析简单的配置信息。数据解析为键值对，键只能是字符串类型, 不能包含:,;。
    key : value,...;
    value: int,float,str,list.
eg:
k1: 30, K2 :3.14, k3:"qazxsw", 123 : [12, 34], ??^#^#: [56, 78.9];
(int, double, TCHAR*, int[2], double[2])
*seekKey("k1") -> 30
*(p=seekKey("123"))-> 12
*seekNextValue("123", p) -> 34
*/

#ifndef _ARGPARSE_H
#define _ARGPARSE_H
#ifndef _ARGPARSEAPI
#define _ARGPARSEAPI extern "C" __declspec(dllimport)
#endif
#include <BasicObject.h>

typedef struct ArgDict
{
    BOBJECT keys;
    BOBJECT values;
    BOBJECT contact;
    int16_t idx;
}ArgDict;

_ARGPARSEAPI ArgDict CreateArgDict();
_ARGPARSEAPI void    AD_AppendInt        (ArgDict *self, TCHAR *key, BOINT i);
_ARGPARSEAPI void    AD_AppendFloat      (ArgDict *self, TCHAR *key, BOFLOAT f);
_ARGPARSEAPI void    AD_AppendString     (ArgDict *self, TCHAR *key, TCHAR *s);
_ARGPARSEAPI void    AD_AppendIntList    (ArgDict *self, TCHAR *key, BOINT *lo, int16_t len);
_ARGPARSEAPI void    AD_AppendFloatList  (ArgDict *self, TCHAR *key, BOFLOAT *lo, int16_t len);
_ARGPARSEAPI void    AD_AppendStringList (ArgDict *self, TCHAR *key, TCHAR *s[], int16_t len);

_ARGPARSEAPI bo_datum* AD_SeekKey        (ArgDict *self, TCHAR *key);
_ARGPARSEAPI bo_datum* AD_SeekNextValue  (ArgDict *self, TCHAR *key, bo_datum *prev);//prev = AD_SeekKey()
_ARGPARSEAPI bo_datum  AD_GetValue       (ArgDict *self, TCHAR *key, bo_datum *_Default);
_ARGPARSEAPI bo_datum  AD_GetNextValue   (ArgDict *self, TCHAR *key, bo_datum *prev, bo_datum *_Default);

//_ARGPARSEAPI errno_t AD_ReadString(ArgDict *self, TCHAR *str);
//_ARGPARSEAPI errno_t AD_ReadText(ArgDict *self, TCHAR *filename);

_ARGPARSEAPI errno_t   AD_ParseCmdLn     (ArgDict *self, const TCHAR *cmd, TCHAR sep);//xxx[sep]xxx...

_ARGPARSEAPI errno_t   AD_FreeArgDict    (ArgDict *self);
_ARGPARSEAPI TCHAR *   AD_ConvertToReadableFormat(ArgDict *self, TCHAR *to);

_ARGPARSEAPI _Bool     isInteger         (const TCHAR* itstr);
_ARGPARSEAPI _Bool     isDecimal         (TCHAR *s);

#endif